"""
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.

"""

from PyQt4 import QtGui
from msnp.model import PTPModel
from msnp.gui import UIText

class GroupDetailType():
    """Class containing the four types with which a group details widget can be opened.
    It is one of "OWNER", "MEMBER", "NOT_MEMBER" or "NEW_GROUP"."""
    
    OWNER = 'owner'
    MEMBER = 'member'
    NOT_MEMBER = 'not_member'
    NEW_GROUP = 'new_group'
    
def returnTypeToString(type):
    """This function returns the given ReturnType object as readable String."""
    if type == PTPModel.ReturnType.ERROR:
        return UIText.MSG_ERROR_STANDARD
    elif type == PTPModel.ReturnType.LOGIN_WRONG_USERNAME:
        return UIText.MSG_ERROR_LOGIN_WRONG_USERNAME
    elif type == PTPModel.ReturnType.LOGIN_WRONG_PASSWORD:
        return UIText.MSG_ERROR_LOGIN_WRONG_PASSWORD
    elif type == PTPModel.ReturnType.REGISTER_NAME_NOT_AVAILABLE:
        return UIText.MSG_ERROR_REGISTER_NAME_NOT_AVAILABLE
    elif type == PTPModel.ReturnType.AUTHENTICATION_NO_PASSWORD:
        return UIText.MSG_ERROR_AUTHENTICATION_NO_PASSWORD
    elif type == PTPModel.ReturnType.GROUP_ALREADY_EXISTS:
        return UIText.MSG_ERROR_GROUP_ALREADY_EXISTS
    elif type == PTPModel.ReturnType.PEER_OFFLINE:
        return UIText.MSG_ERROR_PEER_OFFLINE
    elif type == PTPModel.ReturnType.ALREADY_LOGGED_IN:
        return UIText.MSG_ERROR_ALREADY_LOGGED_IN
    elif type == PTPModel.ReturnType.NO_KNOWN_PEER_ONLINE:
        return UIText.MSG_ERROR_NO_KNOWN_PEER_ONLINE
    elif type == PTPModel.ReturnType.NO_PLAYER_SELECTED:
        return UIText.MSG_ERROR_NO_PLAYER_SELECTED
    else:
        return UIText.MSG_ERROR_STANDARD
    
def chatStatusToString(status):
    """This function returns the given ChatMessageStatus object as readable String."""
    if status == PTPModel.ChatMessageStatus.SENDING:
        return UIText.MSG_CHAT_STATUS_SENDING
    elif status == PTPModel.ChatMessageStatus.SENT:
        return UIText.MSG_CHAT_STATUS_SENT
    elif status == PTPModel.ChatMessageStatus.PEER_OFFLINE:
        return UIText.MSG_CHAT_STATUS_PEER_OFFLINE
    elif status == PTPModel.ChatMessageStatus.PEER_NOT_EXISTENT:
        return UIText.MSG_CHAT_STATUS_PEER_NOT_EXISTENT
    elif status == PTPModel.ChatMessageStatus.RECEIVED:
        return ""
    return UIText.MSG_CHAT_STATUS_SENT

def centerWidget(widget):
    """This function centers the given widget on the screen."""
#    size = widget.size()
#    desktopWidget = QtGui.QApplication.desktop()
#    screenWidth = desktopWidget.width()
#    screenHeight = desktopWidget.height()
#    wWidth = size.width()
#    wHeight = size.height()
#    moveW = (screenWidth / 2) - (wWidth / 2)
#    moveH = (screenHeight / 2) - (wHeight / 2) 
#    widget.move(moveW, moveH)
    screen = QtGui.QDesktopWidget().screenGeometry()
    size =  widget.geometry()
    widget.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)

    
def splitLongWords(message):
    """This function inserts a whitespace into words of the given message when they have more than 30 letters."""
    modifiedMsg = ""
    counter = 0
    for char in message:
        if char == " ":
            counter = 0
        else:
            counter += 1
        if counter == 30:
            char += " "
            counter = 0
        modifiedMsg += char
    return modifiedMsg
